package com.example.spsaveqqty;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.sug.OnGetSuggestionResultListener;
import com.baidu.mapapi.search.sug.SuggestionResult;
import com.baidu.mapapi.search.sug.SuggestionSearch;
import com.baidu.mapapi.search.sug.SuggestionSearchOption;
import com.example.spsaveqqty.attraction.AtractionsActivity;
import com.example.spsaveqqty.attraction.Attraction;
import com.example.spsaveqqty.attraction.AttractionDao;
import com.example.spsaveqqty.guides.Guide;
import com.example.spsaveqqty.guides.GuidesMainActivity;
import com.example.spsaveqqty.util.logUtil;
import com.google.gson.Gson;

import java.io.Serializable;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

import interfaces.heweather.com.interfacesmodule.bean.Code;
import interfaces.heweather.com.interfacesmodule.bean.Lang;
import interfaces.heweather.com.interfacesmodule.bean.Unit;
import interfaces.heweather.com.interfacesmodule.bean.weather.hourly.Hourly;
import interfaces.heweather.com.interfacesmodule.bean.weather.hourly.HourlyBase;
import interfaces.heweather.com.interfacesmodule.bean.weather.now.Now;
import interfaces.heweather.com.interfacesmodule.bean.weather.now.NowBase;
import interfaces.heweather.com.interfacesmodule.view.HeConfig;
import interfaces.heweather.com.interfacesmodule.view.HeWeather;


public class map_weather extends AppCompatActivity {
    //百度地图监听器
    LocationClient mLocationClient;
    //百度地图组件
    MapView mapView;
    //百度地图总控制器
    BaiduMap baiduMap;
    //地图定位图标Marker
    BitmapDescriptor mapMark;
    //是否允许执行定位
    boolean is_Locate = false;
    //boolean is_normal_map = true;

    //当前天气及地点组件声明
    TextView placeDate; //天气数据时间
    TextView placeName; //天气数据对应区域
    TextView placeNowWeather;  //对应区域当前天气

    //逐小时天气详情显示组件集合
    List<TextView> temperatureList;
    List<TextView> cloudList;
    List<TextView> humidityList;
    List<TextView> rainList;
    List<ImageView> weatherIconList;

    //private ImageView map_type;
    //地图天气搜索栏
    EditText search_text;
    //联想搜索列表所在布局
    ConstraintLayout searchList;
    //联想搜索结果的显示组件集合
    List<TextView> SearchResultList;
    //百度地图搜索的监听器
    SuggestionSearch mSuggestionSearch;

    //未来逐小时具体时间集合
    List<TextView> TimeList;
    //未来逐小时具体天气情况
    List<HourlyBase> hourlyTempList;

    //所预报的未来天气次序数
    int Weather_day = 0;
    //用于重置某一地点的地图天气页面的当前城市区域和经纬度
    String reload_city;
    double reload_lat;
    double reload_lon;

    boolean is_FirstIntent = false;
    String needPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //和风天气密钥
        HeConfig.init("HE2005291532001710", "5458914e7b6c45e38c89167dfc7dbb79");
        //HeConfig.switchToFreeServerNode();  //免费版转换服务器
        //提示开启定位服务的关键信息
        Toast toast = Toast.makeText(map_weather.this,"!!!在执行本模块的一切功能前需要手动打开手机的位置信息服务",Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();
        //判断是否由其它模块携地址跳转而来
        Intent intent = getIntent();
        needPosition = intent.getStringExtra("position_name");
        System.out.println("need location = "+needPosition);
        if(needPosition!=null && needPosition!=""){
            is_FirstIntent = true;
        }
        //开启地图
        setBDMap();
        //初始化天气
        initWeather();

    }


    //设置地图定位控制按钮和模块导航按钮
    public void setLocationButton(){
        ImageButton locateButton = (ImageButton) findViewById(R.id.location_button);
        locateButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                searchList.setVisibility(View.INVISIBLE);
                is_Locate = true;
            }
        });

        //本模块到攻略主模块的跳转
        ImageButton ib_main = (ImageButton)findViewById(R.id.imageButton2);
        ib_main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v){
                Intent intent = new Intent(map_weather.this, GuidesMainActivity.class);
                startActivity(intent);
                finish();
            }
        });

        //本模块到景点子模块的跳转
        ImageButton ib_scenic = (ImageButton)findViewById(R.id.imageButton3);
        ib_scenic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v){

                AttractionDao dao = new AttractionDao(map_weather.this);
                List<Attraction> rankList = null;
                rankList = dao.selectByOrder();

                Intent intent = new Intent(map_weather.this, AtractionsActivity.class);
                intent.putExtra("rkList", (Serializable) rankList);
                startActivity(intent);
            }
        });
    }

    //使按返回键时直接返回个人中心：
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //点击home键
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            return true;
        }
        //点击返回键
        else if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent intent = new Intent(map_weather.this, GuidesMainActivity.class);
            startActivity(intent);
            setResult(RESULT_OK, intent);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


    //设置搜索框
    public void setSearchOption(){
        search_text=(EditText)findViewById(R.id.search_text);
        search_text.addTextChangedListener(new TextWatcher(){
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(s.length()>0){
                    is_Locate = false;
                    mSuggestionSearch.requestSuggestion((new SuggestionSearchOption()).keyword(search_text.getText().toString()).city("成都"));
                    searchList.setVisibility(View.VISIBLE);
                }
                if(s.length()==0||s.equals(" ")){
                    searchList.setVisibility(View.INVISIBLE);
                }
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
    }

    private void setBDMap(){
        mLocationClient = new LocationClient(getApplicationContext());
        mLocationClient.registerLocationListener(new MyLocationListener()); //注册定位监听器，获取到位置信息后将回调
        SDKInitializer.initialize(getApplicationContext());//传入全局Context参数以初始化
        setContentView(R.layout.activity_map);  //结果展示的布局
        mapView =findViewById(R.id.bmapView); //获取百度地图组件
        baiduMap = mapView.getMap(); //通过地图组件获取百度地图的总控制器
        baiduMap.setMyLocationEnabled(true); //开启在地图上显示当前位置的功能
//        baiduMap.setMapType(is_normal_map?BaiduMap.MAP_TYPE_SATELLITE:BaiduMap.MAP_TYPE_NORMAL); //地图类型：卫星地图//MAP_TYPE_NORMAL
        baiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); //地图类型：卫星地图//MAP_TYPE_NORMAL
        baiduMap.setTrafficEnabled(true); //显示通路
        mSuggestionSearch = SuggestionSearch.newInstance();
        mSuggestionSearch.setOnGetSuggestionResultListener(listener);

        //权限申请
        List<String> permissionList = new ArrayList<>();
        if (ContextCompat.checkSelfPermission(map_weather.this,Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
            permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
        }
        if (ContextCompat.checkSelfPermission(map_weather.this, Manifest.permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED){
            permissionList.add(Manifest.permission.READ_PHONE_STATE);
        }
        if (ContextCompat.checkSelfPermission(map_weather.this,Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
            permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        }
        if(!permissionList.isEmpty()){
            String[] permissions = permissionList.toArray(new String[permissionList.size()]);
            ActivityCompat.requestPermissions(map_weather.this,permissions,1);
        }else{
            requestLocation(); //权限赋予通过才执行定位
        }
    }

    //执行定位之前的权限赋予
    @Override
    public void onRequestPermissionsResult(int requestCode,String[] permissions,int[] grantResults){
        switch(requestCode){
            case 1:
                if(grantResults.length > 0){
                    for(int result : grantResults){
                        if(result != PackageManager.PERMISSION_GRANTED){
                            Toast.makeText(this, "必须同意所有权限才能使用本程序", Toast.LENGTH_SHORT).show();
                            finish();
                            return;
                        }
                    }
                    requestLocation();
                }else{
                    Toast.makeText(this,"发生未知错误",Toast.LENGTH_SHORT).show();
                    finish();
                }
                break;
            default:
        }
    }

    //接收定位请求
    private void requestLocation(){
        initLocation();
        mLocationClient.start(); //开始定位，定位结果将回调到监听器中
    }

    //百度地图定位初始化设置
    private void initLocation(){
        LocationClientOption option = new LocationClientOption();
        option.setScanSpan(1000); //设置定位更新间隔为1000毫秒
        //option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); //GPS定位和网络定位均可
        option.setIsNeedAddress(true); //需要获取当前位置的详细信息
        mLocationClient.setLocOption(option); //配置入监听器

    }


    //百度联想搜索的监听器
    OnGetSuggestionResultListener listener = new OnGetSuggestionResultListener() {
        @Override
        public void onGetSuggestionResult(SuggestionResult res) {
            if(res == null || res.getAllSuggestions() == null){
                //未找到相关结果
                return;
            }else{
                //获取在线搜索结果
                List <SuggestionResult.SuggestionInfo> resl = res.getAllSuggestions();
                int num = resl.size();
                System.out.println("SuggestionResult number = "+num);
                int i = 0;
                Log.i("INFO", "Baidu suggestionResult onSuccess:" + new Gson().toJson(resl));
                for (i = 0; i<num; i++) {
                    searchList.setVisibility(View.VISIBLE);
                    SearchResultList.get(i).setText(resl.get(i).city+resl.get(i).district+resl.get(i).key);
                    if(!resl.get(i).city.equals("")){
                        if(resl.get(i).city.contains("自治州")){
                            SearchResultList.get(i).setContentDescription(resl.get(i).getDistrict()+"!"+resl.get(i).pt);
                        }else{
                            SearchResultList.get(i).setContentDescription(resl.get(i).getCity()+"!"+resl.get(i).pt);
                        }
                    }
                    else{
                        //不显示省份级别的地图及天气
                        SearchResultList.get(i).setContentDescription("");
                        System.out.println("过滤的凭证"+resl.get(i).city);
                        System.out.println("过滤的地名:"+resl.get(i).getKey());
                    }
                }

            }
        }
    };

    //定位监听器
    public class MyLocationListener implements BDLocationListener{
        @Override
        public void onReceiveLocation(final BDLocation location) {
            if((location.getLocType() == BDLocation.TypeGpsLocation || location.getLocType() == BDLocation.TypeNetWorkLocation) && is_Locate==true){
                //当为GPS定位或者网络定位时均可，调用navigateTo，移动地图到所在位置
                try {
                    double lat = location.getLatitude();
                    double lon = location.getLongitude();
                    navigateTo(lat,lon,location.getCity());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
            is_Locate = false;  //一次定位后不自动持续更新即时信息，减轻系统负担
        }
        public void onConnectHotSpotMessage(String s, int i){}
    }

    //通过经纬度切换地图，通过所在城市名切换天气信息
    private void navigateTo(double latitude,double longitude,String city) throws MalformedURLException {
        reload_lat = latitude;
        reload_lon = longitude;
        System.out.println("navigateTo="+reload_lat+","+reload_lon);
        LatLng ll = new LatLng(latitude,longitude);//LatLng对象用于存放经纬度值
        baiduMap.clear();
        mapMark = BitmapDescriptorFactory.fromResource(R.drawable.map_loc);   //定位marker初始化
        MarkerOptions option = new MarkerOptions().position(ll).icon(mapMark);
        baiduMap.addOverlay(option);
        MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll); //传入LatLng对象获取MapStatusUpdate 对象
        baiduMap.animateMapStatus(update); //传入MapStatusUpdate对象更新BaiduMap对象
        update = MapStatusUpdateFactory.zoomTo(13f); //缩放级别应该在3到19之间，越大越精细
        baiduMap.animateMapStatus(update); //传入MapStatusUpdate对象更新BaiduMap对象
        //定位更新位置
        MyLocationData.Builder locationBuilder = new MyLocationData.Builder(); //Builder对象
        locationBuilder.latitude(latitude);
        locationBuilder.longitude(longitude);
        MyLocationData locationData = locationBuilder.build();  //Builder对象调用build方法返回MyLocationData对象
        baiduMap.setMyLocationData(locationData); //将MyLocationData对象传入中控制器的setMyLocationData方法，设置所要显示的当前位置
        //天气信息更新
        setForeCastWeather(city);

        //根据是否从其它模块携地点名position_name跳转来，决定初始定位之后是否根据特定信息搜索地点项（需要整合）

        if(is_FirstIntent){
            //改变搜索框中的值来触发联想搜索
            search_text.requestFocus();//获取焦点
            search_text.setText(needPosition);
            is_FirstIntent = false;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    //停止定位
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLocationClient.stop();//活动被销毁时停止定位，不在后台运行
        mapView.onDestroy(); //活动销毁时销毁
        baiduMap.setMyLocationEnabled(false); //活动被销毁时关闭显示当前位置图标的功能
    }

    //天气组件的获取和初始化
    public void initWeather(){
        TextView humidity1;
        TextView rain1;
        ImageView weatherIcon1;

        TextView temperature2;
        TextView cloud2;
        TextView humidity2;
        TextView rain2;
        ImageView weatherIcon2;

        TextView temperature3;
        TextView cloud3;
        TextView humidity3;
        TextView rain3;
        ImageView weatherIcon3;

        TextView temperature4;
        TextView cloud4;
        TextView humidity4;
        TextView rain4;
        ImageView weatherIcon4;

        TextView temperature5;
        TextView cloud5;
        TextView humidity5;
        TextView rain5;
        ImageView weatherIcon5;

        TextView temperature6;
        TextView cloud6;
        TextView humidity6;
        TextView rain6;
        ImageView weatherIcon6;

        TextView temperature7;
        TextView cloud7;
        TextView humidity7;
        TextView rain7;

        TextView searchItem1;
        TextView searchItem2;
        TextView searchItem3;
        TextView searchItem4;
        TextView searchItem5;
        TextView searchItem6;
        TextView searchItem7;
        TextView searchItem8;
        TextView searchItem9;
        TextView searchItem10;

        TextView time_1;
        TextView time_2;
        TextView time_3;
        TextView time_4;
        TextView time_5;
        TextView time_6;
        TextView time_7;


        ImageView preWeather;
        ImageView nextWeather;
        ImageView reloadIcon;

        //显示区域名及天气的组件
        preWeather = findViewById(R.id.icon_preInfo);
        preWeather.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch(Weather_day){
                    case 1:
                        Weather_day = 0;
                        setForeCastWeather(reload_city);
                        break;
                    case 2:
                        Weather_day = 1;
                        setForeCastWeather(reload_city);
                        break;
                    default:
                }
            }
        });
        nextWeather = findViewById(R.id.icon_nextInfo);
        nextWeather.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch(Weather_day){
                    case 0:
                        Weather_day = 1;
                        setForeCastWeather(reload_city);
                        break;
                    case 1:
                        Weather_day = 2;
                        setForeCastWeather(reload_city);
                        break;
                    default:
                }
            }
        });
        placeName = (TextView) findViewById(R.id.place_name);
        placeDate = (TextView) findViewById(R.id.place_date);
        placeNowWeather=(TextView) findViewById(R.id.place_now_weather);

        reloadIcon = findViewById(R.id.icon_reload);
        reloadIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    navigateTo(reload_lat,reload_lon,reload_city);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
        });

//        map_type = findViewById(R.id.is_standard_map);
//        map_type.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(is_normal_map){
//                    map_type.setImageResource(R.drawable.satellite);
//                    is_normal_map = false;
//                    try {
//                        initLocation();
//                        navigateTo(reload_lat,reload_lon,reload_city);
//                    } catch (MalformedURLException e) {
//                        e.printStackTrace();
//                    }
//                }else{
//                    map_type.setImageResource(R.drawable.standardmap);
//                    is_normal_map = true;
//                    try {
//                        initLocation();
//                        navigateTo(reload_lat,reload_lon,reload_city);
//                    } catch (MalformedURLException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        });

        //各时间段的天气信息组件
        TextView temperature1 = (TextView) findViewById(R.id.tp_1);
        temperature2 = (TextView) findViewById(R.id.tp_2);
        temperature3 = (TextView) findViewById(R.id.tp_3);
        temperature4 = (TextView) findViewById(R.id.tp_4);
        temperature5 = (TextView) findViewById(R.id.tp_5);
        temperature6 = (TextView) findViewById(R.id.tp_6);
        temperature7 = (TextView) findViewById(R.id.tp_7);
        temperatureList=new ArrayList<>();
        temperatureList.add(temperature1);
        temperatureList.add(temperature2);
        temperatureList.add(temperature3);
        temperatureList.add(temperature4);
        temperatureList.add(temperature5);
        temperatureList.add(temperature6);
        temperatureList.add(temperature7);

        TextView cloud1 = (TextView) findViewById(R.id.cl_1);
        cloud2 = (TextView) findViewById(R.id.cl_2);
        cloud3 = (TextView) findViewById(R.id.cl_3);
        cloud4 = (TextView) findViewById(R.id.cl_4);
        cloud5 = (TextView) findViewById(R.id.cl_5);
        cloud6 = (TextView) findViewById(R.id.cl_6);
        cloud7 = (TextView) findViewById(R.id.cl_7);
        cloudList=new ArrayList<>();
        cloudList.add(cloud1);
        cloudList.add(cloud2);
        cloudList.add(cloud3);
        cloudList.add(cloud4);
        cloudList.add(cloud5);
        cloudList.add(cloud6);
        cloudList.add(cloud7);

        humidity1 = (TextView) findViewById(R.id.hm_1);
        humidity2 = (TextView) findViewById(R.id.hm_2);
        humidity3 = (TextView) findViewById(R.id.hm_3);
        humidity4 = (TextView) findViewById(R.id.hm_4);
        humidity5 = (TextView) findViewById(R.id.hm_5);
        humidity6 = (TextView) findViewById(R.id.hm_6);
        humidity7 = (TextView) findViewById(R.id.hm_7);
        humidityList=new ArrayList<>();
        humidityList.add(humidity1);
        humidityList.add(humidity2);
        humidityList.add(humidity3);
        humidityList.add(humidity4);
        humidityList.add(humidity5);
        humidityList.add(humidity6);
        humidityList.add(humidity7);

        rain1 = (TextView) findViewById(R.id.rn_1);
        rain2 = (TextView) findViewById(R.id.rn_2);
        rain3 = (TextView) findViewById(R.id.rn_3);
        rain4 = (TextView) findViewById(R.id.rn_4);
        rain5 = (TextView) findViewById(R.id.rn_5);
        rain6 = (TextView) findViewById(R.id.rn_6);
        rain7 = (TextView) findViewById(R.id.rn_7);
        rainList=new ArrayList<>();
        rainList.add(rain1);
        rainList.add(rain2);
        rainList.add(rain3);
        rainList.add(rain4);
        rainList.add(rain5);
        rainList.add(rain6);
        rainList.add(rain7);

        weatherIcon1 = (ImageView)findViewById(R.id.weatherIcon1);
        weatherIcon2 = (ImageView)findViewById(R.id.weatherIcon2);
        weatherIcon3 = (ImageView)findViewById(R.id.weatherIcon3);
        weatherIcon4 = (ImageView)findViewById(R.id.weatherIcon4);
        weatherIcon5 = (ImageView)findViewById(R.id.weatherIcon5);
        weatherIcon6 = (ImageView)findViewById(R.id.weatherIcon6);
        weatherIconList=new ArrayList<>();
        weatherIconList.add(weatherIcon1);
        weatherIconList.add(weatherIcon2);
        weatherIconList.add(weatherIcon3);
        weatherIconList.add(weatherIcon4);
        weatherIconList.add(weatherIcon5);
        weatherIconList.add(weatherIcon6);


        //模糊查询的结果集的显示组件
        searchList =(ConstraintLayout)findViewById(R.id.search_list);

        searchItem1 = (TextView) findViewById(R.id.serach_item1);
        searchItem2= (TextView) findViewById(R.id.serach_item2);
        searchItem3= (TextView) findViewById(R.id.serach_item3);
        searchItem4= (TextView) findViewById(R.id.serach_item4);
        searchItem5= (TextView) findViewById(R.id.serach_item5);
        searchItem6= (TextView) findViewById(R.id.serach_item6);
        searchItem7= (TextView) findViewById(R.id.serach_item7);
        searchItem8= (TextView) findViewById(R.id.serach_item8);
        searchItem9= (TextView) findViewById(R.id.serach_item9);
        searchItem10= (TextView) findViewById(R.id.serach_item10);
        SearchResultList=new ArrayList<>();
        SearchResultList.add(searchItem1);
        SearchResultList.add(searchItem2);
        SearchResultList.add(searchItem3);
        SearchResultList.add(searchItem4);
        SearchResultList.add(searchItem5);
        SearchResultList.add(searchItem6);
        SearchResultList.add(searchItem7);
        SearchResultList.add(searchItem8);
        SearchResultList.add(searchItem9);
        SearchResultList.add(searchItem10);
        //为所有结果项设置监听器
        int i = 0;
        for(i=0;i<10;i++){
            setSearchItemListener(i);
        }

        time_1 = (TextView)findViewById(R.id.time_0);
        time_2 = (TextView)findViewById(R.id.time_4);
        time_3 = (TextView)findViewById(R.id.time_8);
        time_4 = (TextView)findViewById(R.id.time_12);
        time_5 = (TextView)findViewById(R.id.time_16);
        time_6 = (TextView)findViewById(R.id.time_20);
        time_7 = (TextView)findViewById(R.id.time_24);
        TimeList = new ArrayList<>();;
        TimeList.add(time_1);
        TimeList.add(time_2);
        TimeList.add(time_3);
        TimeList.add(time_4);
        TimeList.add(time_5);
        TimeList.add(time_6);
        TimeList.add(time_7);

        //设置定位控制按钮组件及监听器
        setLocationButton();
        //设置搜索框组件及监听器
        setSearchOption();

        //天气组件初始化完毕才可以执行定位
        is_Locate = true;


    }

    //设置地点联想的组件及其监听器
    public void setSearchItemListener(final int index){
        SearchResultList.get(index).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (SearchResultList.get(index).getText().toString().length()!=0)
                {
                    String paraString = SearchResultList.get(index).getContentDescription().toString();
                    if(paraString.equals("")){
                        Toast toast = Toast.makeText(map_weather.this,"！！！省份本身区域过大,无从选择天气地图数据显示,请重新选择下级城市",Toast.LENGTH_SHORT);
                        toast.setGravity(Gravity.CENTER,0,0);
                        toast.show();
                    }else{
                        String [] locaPara = paraString.split("!|: |, |: ");
                        System.out.println("search suggestionResult String = "+ paraString);

                        reload_city = locaPara[0];
                        double lat = Double.parseDouble(locaPara[2]);
                        reload_lat = lat;
                        double lon = Double.parseDouble(locaPara[4]);
                        reload_lon = lon;

                        System.out.println("Search point city = "+reload_city +"lat = "+lat +  ", lon = "+ lon);

                        is_Locate = false;

                        try {
                            navigateTo(lat,lon,reload_city);
                            //点击某一结果项后隐藏搜索集
                            searchList.setVisibility(View.INVISIBLE);
                            search_text.clearFocus();
                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
    }

    //根据所在的城市名切换显示的城市未来逐小时天气预报
    public void setForeCastWeather(final String location) {
        //location = location.substring(0,location.length()-1);
        //System.out.println("set weather location = "+location);
        reload_city = location;
        HeWeather.getWeatherHourly(map_weather.this,location, Lang.CHINESE_SIMPLIFIED,Unit.METRIC, new HeWeather.OnResultWeatherHourlyBeanListener() {
            @Override
            public void onError(Throwable e) {
                logUtil.i("INFO", "Weather hourly onError:" + e.toString());
            }

            @Override
            public void onSuccess(Hourly hourly) {
                Log.i("INFO", "Weather hourly onSuccess:" + new Gson().toJson(hourly));
                //先判断返回的status是否正确，当status正确时获取数据，
                // 若status不正确，可查看status对应的Code值找到原因
                if (Code.OK.getCode().equalsIgnoreCase(hourly.getStatus())) {
                    placeName.setText(hourly.getBasic().getLocation());
                    System.out.println("weather hourly location = "+hourly.getBasic().getLocation());
                    hourlyTempList = hourly.getHourly();

                    int i = 0 ;
                    //i指的是天气图标的显示组件的序号，一次只显示7个
                    for(i=0;i<7;i++){
                        int temp = 24*Weather_day+4*i;
                        temp = temp!=72 ? temp:temp-1;
                        temperatureList.get(i).setText(hourlyTempList.get(temp).getTmp()+"℃");
                        cloudList.get(i).setText(hourlyTempList.get(temp).getCloud()+"%");
                        humidityList.get(i).setText(hourlyTempList.get(temp).getHum()+"%");
                        rainList.get(i).setText(hourlyTempList.get(temp).getPop()+"mm");
                        TimeList.get(i).setText(hourlyTempList.get(temp).getTime().split(" ")[1].split(":")[0]);
                        String cond = hourlyTempList.get(temp).getCond_txt();
                        //System.out.println("ForeCast hourly:"+hourlyTempList.get(temp).getTime()+"= icon"+i+1+"\n");

                        if(i == 0){
                            placeNowWeather.setText(hourlyTempList.get(temp).getCond_txt());
                            placeDate.setText(hourlyTempList.get(temp).getTime());
                        }

                        //图标只显示6个：0-5
                        if(i!=6){
                            int time = Integer.parseInt(TimeList.get(i).getText().toString());
                            boolean isNight = 19<=time&&time<=24 || 0<=time&&time<=7;
                            if (cond.equals("晴") && !isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p100);
                            }else if(cond.equals("晴") && isNight){
                                weatherIconList.get(i).setImageResource(R.drawable.p100n);
                            }else if(cond.equals("多云")){
                                weatherIconList.get(i).setImageResource(R.drawable.p101);
                            } else if (cond.equals("少云")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p102);
                            } else if (cond.equals("晴间多云") && !isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p103);
                            } else if (cond.equals("晴间多云") && isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p103n);
                            } else if (cond.equals("阴") && !isNight){
                                weatherIconList.get(i).setImageResource(R.drawable.p104);
                            } else if (cond.equals("阴") && isNight){
                                weatherIconList.get(i).setImageResource(R.drawable.p104n);
                            } else if (cond.equals("有风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p200);
                            }else if (cond.equals("平静")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p201);
                            }else if (cond.equals("微风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p202);
                            }else if (cond.equals("和风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p203);
                            }else if (cond.equals("清风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p204);
                            }else if (cond.equals("强风/劲风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p205);
                            }else if (cond.equals("疾风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p206);
                            }else if (cond.equals("大风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p207);
                            }else if (cond.equals("烈风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p208);
                            }else if (cond.equals("风暴")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p209);
                            }else if (cond.equals("狂爆风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p210);
                            }else if (cond.equals("飓风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p211);
                            }else if (cond.equals("龙卷风")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p212);
                            }else if (cond.equals("热带风暴")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p213);
                            }else if (cond.equals("强阵雨") && !isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p300);
                            }else if (cond.equals("强阵雨") && isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p300n);
                            }else if (cond.equals("阵雨") && !isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p301);
                            }else if (cond.equals("阵雨") && isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p301n);
                            }else if (cond.equals("雷阵雨") ) {
                                weatherIconList.get(i).setImageResource(R.drawable.p302);
                            }else if (cond.equals("强雷阵雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p303);
                            }else if (cond.equals("雷阵雨伴有冰雹")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p304);
                            }else if (cond.equals("小雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p305);
                            }else if (cond.equals("中雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p306);
                            }else if (cond.equals("大雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p307);
                            }else if (cond.equals("极端降雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p308);
                            }else if (cond.equals("毛毛雨/细雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p309);
                            }else if (cond.equals("暴雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p310);
                            }else if (cond.equals("大暴雨") ) {
                                weatherIconList.get(i).setImageResource(R.drawable.p311);
                            }else if (cond.equals("特大暴雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p312);
                            }else if (cond.equals("冻雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p313);
                            }else if (cond.equals("小到中雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p314);
                            }else if (cond.equals("中到大雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p315);
                            }else if (cond.equals("大到暴雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p316);
                            }else if (cond.equals("暴雨到大暴雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p317);
                            }else if (cond.equals("大暴雨到特大暴雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p318);
                            }else if (cond.equals("雨")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p399);
                            }else if (cond.equals("小雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p400);
                            }else if (cond.equals("中雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p401);
                            }else if (cond.equals("大雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p402);
                            }else if (cond.equals("暴雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p403);
                            }else if (cond.equals("雨夹雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p404);
                            }else if (cond.equals("雨雪天气")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p405);
                            }else if (cond.equals("阵雨夹雪") && !isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p406);
                            }else if (cond.equals("阵雨夹雪") && isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p406n);
                            }else if (cond.equals("阵雪") && !isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p407);
                            }else if (cond.equals("阵雪") && isNight) {
                                weatherIconList.get(i).setImageResource(R.drawable.p407n);
                            }else if (cond.equals("小到中雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p408);
                            }else if (cond.equals("中到大雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p409);
                            }else if (cond.equals("大到暴雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p410);
                            }else if (cond.equals("雪")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p499);
                            }else if (cond.equals("薄雾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p500);
                            }else if (cond.equals("雾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p501);
                            }else if (cond.equals("霾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p502);
                            }else if (cond.equals("扬沙")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p503);
                            }else if (cond.equals("浮尘")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p504);
                            } else if (cond.equals("沙尘暴")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p507);
                            }else if (cond.equals("强沙尘暴")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p508);
                            }else if (cond.equals("浓雾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p509);
                            }else if (cond.equals("强浓雾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p510);
                            }else if (cond.equals("中度霾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p511);
                            }else if (cond.equals("重度霾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p512);
                            }else if (cond.equals("严重霾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p513);
                            }else if (cond.equals("大雾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p514);
                            }else if (cond.equals("特强浓雾")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p515);
                            }else if (cond.equals("热")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p900);
                            }else if (cond.equals("冷")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p901);
                            }else if (cond.equals("未知")) {
                                weatherIconList.get(i).setImageResource(R.drawable.p999);
                            } else {
                                weatherIconList.get(i).setImageResource(R.drawable.map_fly_u10);
                                System.out.println("i:" + cond);
                            }
                        }
                    }
                    //根据是否查询当日未来一天天气来决定是否调用设置当前时刻天气的方法
                    if(Weather_day == 0){
                        setNowWeather(location);
                    }
                }
                else{
                    //若获取失败则打印出错误原因
                    String status = hourly.getStatus();
                    Code code = Code.toEnum(status);
                    logUtil.i("INFO", "failed code: " + code);
                }
            }
        });



    }

    //设置当前时刻天气
    public void setNowWeather(final String location){
        HeWeather.getWeatherNow(map_weather.this,location, Lang.CHINESE_SIMPLIFIED,Unit.METRIC, new HeWeather.OnResultWeatherNowBeanListener() {
            @Override
            public void onError(Throwable e) {
                logUtil.i("INFO", "Weather now onError:" + e.toString());
            }

            @Override
            public void onSuccess(Now now) {
                Log.i("INFO", "Weather now onSuccess:" + new Gson().toJson(now));
                //先判断返回的status是否正确，当status正确时获取数据，
                // 若status不正确，可查看status对应的Code值找到原因
                if (Code.OK.getCode().equalsIgnoreCase(now.getStatus())) {
                    placeDate.setText(now.getUpdate().getLoc());
                    System.out.println("weather now location = "+now.getBasic().getLocation());
                    NowBase nowDate = now.getNow();
                    placeNowWeather.setText(nowDate.getCond_txt());

                    //为天气详细信息显示组件赋值
                    temperatureList.get(0).setText( nowDate.getTmp().toString()+"℃");
                    cloudList.get(0).setText(nowDate.getCloud().toString()+"%");
                    humidityList.get(0).setText(nowDate.getHum().toString()+"%");
                    rainList.get(0).setText(nowDate.getPcpn().toString()+"%");
                    String cond = nowDate.getCond_txt();

                    //根据当前时刻判断是否使用夜间图标
                    int NowClock =  Integer.parseInt(placeDate.getText().toString().split(" ")[1].split(":")[0]);
                    boolean isNight = (19<=NowClock && NowClock<=24)|| (0<=NowClock && NowClock<=7);
                    if (cond.equals("晴") && !isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p100);
                    }else if(cond.equals("晴") && isNight){
                        weatherIconList.get(0).setImageResource(R.drawable.p100n);
                    }else if(cond.equals("多云")){
                        weatherIconList.get(0).setImageResource(R.drawable.p101);
                    } else if (cond.equals("少云")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p102);
                    } else if (cond.equals("晴间多云") && !isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p103);
                    } else if (cond.equals("晴间多云") && isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p103n);
                    } else if (cond.equals("阴") && !isNight){
                        weatherIconList.get(0).setImageResource(R.drawable.p104);
                    } else if (cond.equals("阴") && isNight){
                        weatherIconList.get(0).setImageResource(R.drawable.p104n);
                    } else if (cond.equals("有风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p200);
                    }else if (cond.equals("平静")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p201);
                    }else if (cond.equals("微风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p202);
                    }else if (cond.equals("和风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p203);
                    }else if (cond.equals("清风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p204);
                    }else if (cond.equals("强风/劲风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p205);
                    }else if (cond.equals("疾风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p206);
                    }else if (cond.equals("大风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p207);
                    }else if (cond.equals("烈风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p208);
                    }else if (cond.equals("风暴")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p209);
                    }else if (cond.equals("狂爆风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p210);
                    }else if (cond.equals("飓风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p211);
                    }else if (cond.equals("龙卷风")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p212);
                    }else if (cond.equals("热带风暴")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p213);
                    }else if (cond.equals("强阵雨") && !isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p300);
                    }else if (cond.equals("强阵雨") && isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p300n);
                    }else if (cond.equals("阵雨") && !isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p301);
                    }else if (cond.equals("阵雨") && isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p301n);
                    }else if (cond.equals("雷阵雨") ) {
                        weatherIconList.get(0).setImageResource(R.drawable.p302);
                    }else if (cond.equals("强雷阵雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p303);
                    }else if (cond.equals("雷阵雨伴有冰雹")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p304);
                    }else if (cond.equals("小雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p305);
                    }else if (cond.equals("中雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p306);
                    }else if (cond.equals("大雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p307);
                    }else if (cond.equals("极端降雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p308);
                    }else if (cond.equals("毛毛雨/细雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p309);
                    }else if (cond.equals("暴雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p310);
                    }else if (cond.equals("大暴雨") ) {
                        weatherIconList.get(0).setImageResource(R.drawable.p311);
                    }else if (cond.equals("特大暴雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p312);
                    }else if (cond.equals("冻雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p313);
                    }else if (cond.equals("小到中雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p314);
                    }else if (cond.equals("中到大雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p315);
                    }else if (cond.equals("大到暴雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p316);
                    }else if (cond.equals("暴雨到大暴雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p317);
                    }else if (cond.equals("大暴雨到特大暴雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p318);
                    }else if (cond.equals("雨")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p399);
                    }else if (cond.equals("小雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p400);
                    }else if (cond.equals("中雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p401);
                    }else if (cond.equals("大雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p402);
                    }else if (cond.equals("暴雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p403);
                    }else if (cond.equals("雨夹雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p404);
                    }else if (cond.equals("雨雪天气")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p405);
                    }else if (cond.equals("阵雨夹雪") && !isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p406);
                    }else if (cond.equals("阵雨夹雪") && isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p406n);
                    }else if (cond.equals("阵雪") && !isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p407);
                    }else if (cond.equals("阵雪") && isNight) {
                        weatherIconList.get(0).setImageResource(R.drawable.p407n);
                    }else if (cond.equals("小到中雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p408);
                    }else if (cond.equals("中到大雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p409);
                    }else if (cond.equals("大到暴雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p410);
                    }else if (cond.equals("雪")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p499);
                    }else if (cond.equals("薄雾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p500);
                    }else if (cond.equals("雾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p501);
                    }else if (cond.equals("霾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p502);
                    }else if (cond.equals("扬沙")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p503);
                    }else if (cond.equals("浮尘")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p504);
                    } else if (cond.equals("沙尘暴")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p507);
                    }else if (cond.equals("强沙尘暴")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p508);
                    }else if (cond.equals("浓雾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p509);
                    }else if (cond.equals("强浓雾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p510);
                    }else if (cond.equals("中度霾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p511);
                    }else if (cond.equals("重度霾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p512);
                    }else if (cond.equals("严重霾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p513);
                    }else if (cond.equals("大雾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p514);
                    }else if (cond.equals("特强浓雾")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p515);
                    }else if (cond.equals("热")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p900);
                    }else if (cond.equals("冷")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p901);
                    }else if (cond.equals("未知")) {
                        weatherIconList.get(0).setImageResource(R.drawable.p999);
                    } else {
                        weatherIconList.get(0).setImageResource(R.drawable.map_fly_u10);
                        System.out.println("now weather:" + cond);
                    }

                }
                else{
                    //若获取失败则打印出错误原因
                    String status = now.getStatus();
                    Code code = Code.toEnum(status);
                    logUtil.i("INFO", "failed code: " + code);
                }
            }
        });

    }
}
